package com.wqtz.chechai.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Toast;

import com.wqtz.chechai.R;
import com.wqtz.chechai.base.lvbaseadapter.LvBaseAdapter;
import com.wqtz.chechai.base.lvbaseadapter.ViewHolder;
import com.wqtz.chechai.bean.MessageBean;
import com.wqtz.chechai.utils.LogUtils;
import com.wqtz.chechai.utils.SPUtils;
import com.wqtz.chechai.view.activities.ApprovalInfoActivity;
import com.yinglan.swiperefresh.SwipeMenu;
import com.yinglan.swiperefresh.SwipeMenuListView;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目名称： CheChai
 * 创建人 :  Kisum
 * 创建时间: 2017/2/16
 */

public class MessageFragmentAdapter extends LvBaseAdapter<MessageBean> implements SwipeMenuListView.OnMenuItemClickListener {
    private List<MessageBean> mDatas = new ArrayList<>();
    /**
     * 2种状态：公司公告 审批信息
     */
    private final int COMPANY_NOTICE = 0;
    private final int APPROVAL_NOTICE = 1;
    private Context mContext;


    public MessageFragmentAdapter(Context context, int resId) {
        super(resId);
        mContext = context;
    }


    @Override
    public void bindDatas(final List<MessageBean> list, final int position, ViewHolder holder) {
        mDatas.clear();
        mDatas.addAll(list);
        MessageBean messageBean = list.get(position);
        holder.setText(R.id.tv_time, messageBean.getMessageTime());
        holder.setText(R.id.company_notice_detail, messageBean.getMessageInfo());
        holder.setCirCleImag(R.id.iv_status,R.drawable.message_new_notice);
        switch (messageBean.getMessageType()) {
            /**
             * 2种状态：公司公告 审批信息
             */
            case COMPANY_NOTICE:
                //公司公告
                holder.setCirCleImag(R.id.iv_message_type, R.drawable.message_wanqiao);
                //信息title
                holder.setText(R.id.notice_type, "公司公告");
                break;
            case APPROVAL_NOTICE:
                //审批消息
                holder.setCirCleImag(R.id.iv_message_type, R.drawable.message_approval);
                //信息title
                holder.setText(R.id.notice_type, "审批消息");
                break;
        }

    }

    @Override
    public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
        switch (index) {
            case 0:
                Toast.makeText(mContext, "delete", Toast.LENGTH_SHORT).show();
                mDatas.remove(position);
                clearData();
                addData(mDatas);
                break;
            case 1:
                Toast.makeText(mContext, "查看", Toast.LENGTH_SHORT).show();
                toApprovalInfoActivity(position);
                break;
        }
        return false;
    }


    //跳转到审批消息
    private void toApprovalInfoActivity(int position) {
        //
        Intent intent = new Intent(mContext, ApprovalInfoActivity.class);
        MessageBean messageBean = mDatas.get(position);
        intent.putExtra("type", messageBean.getMessageType());
        mContext.startActivity(intent);
    }


}
